
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
testcontainers
Advanced tools
Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container
The testcontainers npm package is a library that provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. It is primarily used for integration testing, allowing developers to run tests against real instances of services without the overhead of managing those services manually.
Running a PostgreSQL container
This feature allows you to run a PostgreSQL container for testing purposes. The code sample demonstrates how to start a PostgreSQL container with a specified password and expose the default port.
const { GenericContainer } = require('testcontainers');
(async () => {
const container = await new GenericContainer('postgres')
.withEnv('POSTGRES_PASSWORD', 'password')
.withExposedPorts(5432)
.start();
console.log(`PostgreSQL started on port ${container.getMappedPort(5432)}`);
})();
Running a Redis container
This feature allows you to run a Redis container for testing purposes. The code sample demonstrates how to start a Redis container and expose the default port.
const { GenericContainer } = require('testcontainers');
(async () => {
const container = await new GenericContainer('redis')
.withExposedPorts(6379)
.start();
console.log(`Redis started on port ${container.getMappedPort(6379)}`);
})();
Running a custom Docker container
This feature allows you to run any custom Docker container for testing purposes. The code sample demonstrates how to start a custom Docker container and expose a specified port.
const { GenericContainer } = require('testcontainers');
(async () => {
const container = await new GenericContainer('your-custom-image')
.withExposedPorts(8080)
.start();
console.log(`Custom container started on port ${container.getMappedPort(8080)}`);
})();
Dockerode is a Docker client for Node.js. It provides a way to interact with Docker containers programmatically. While it offers more control and flexibility over Docker operations, it lacks the high-level abstractions and ease of use that testcontainers provides for integration testing.
Node-docker-api is another Docker client for Node.js. Similar to dockerode, it allows for programmatic interaction with Docker containers. However, it does not provide the same level of convenience and specialized features for testing as testcontainers.
See LICENSE.
Copyright (c) 2018 - 2023 Cristian Greco and other authors.
See CONTRIBUTING.md for how to contribute to this repo.
See contributors for all contributors.
Join our Slack workspace | Testcontainers OSS | Testcontainers Cloud
FAQs
Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container
The npm package testcontainers receives a total of 514,755 weekly downloads. As such, testcontainers popularity was classified as popular.
We found that testcontainers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.